package cn.itsource.pet.controller;

import cn.itsource.basic.dto.OrderDto;
import cn.itsource.pet.service.IOrderPetAcquisitionService;
import cn.itsource.pet.domain.OrderPetAcquisition;
import cn.itsource.pet.query.OrderPetAcquisitionQuery;
import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetAcquisitionController {

    @Autowired
    public IOrderPetAcquisitionService orderPetAcquisitionService;

    /**
     * 接口：添加或修改
     * @param orderPetAcquisition  传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping("/save")
    public AjaxResult addOrUpdate(@RequestBody OrderPetAcquisition orderPetAcquisition){
        if( orderPetAcquisition.getId()!=null){
		orderPetAcquisitionService.update(orderPetAcquisition);
        }else{
                orderPetAcquisitionService.insert(orderPetAcquisition);
	}
        return new AjaxResult();

    }

    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        orderPetAcquisitionService.delete(id);
        return new AjaxResult();
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping("/patchDelete")
    public AjaxResult patchDel(@RequestBody List<Long> ids){
        orderPetAcquisitionService.patchDelete(ids);
        return new AjaxResult();
    }

    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/selectById/{id}")
    public OrderPetAcquisition findOne(@PathVariable("id")Long id) {
        return orderPetAcquisitionService.selectById(id);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping("/selectAll")
    public List<OrderPetAcquisition> findAll(){
        return orderPetAcquisitionService.selectAll();
    }


   /**
    * 接口：分页查询或高级查询
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/selectByQueryPage")
    public PageResult<OrderPetAcquisition> queryPage(@RequestBody OrderPetAcquisitionQuery query, HttpServletRequest request) {
        return orderPetAcquisitionService.queryPage(query,request);
    }

    @PostMapping("/confirm")
    public AjaxResult confirm(@RequestBody OrderDto orderDto) {
        return orderPetAcquisitionService.comfirm(orderDto);
    }

    @DeleteMapping("/cancle/{id}")
    public AjaxResult cancle(@PathVariable("id") Long id) {
        return orderPetAcquisitionService.cancle(id);
    }


















}
